package chess_game_5;

import java.util.Arrays;

//子类，peace模式
//extend关键字
public class PeaceGame extends Game {
    public PeaceGame(String player1, String player2, int gameId) {
        super(player1, player2, gameId, "peace");
    }

    @Override
    public void initializeBoard() {
        board = new char[Chess.BOARD_SIZE][Chess.BOARD_SIZE];
        for (char[] row : board) {
            Arrays.fill(row, Chess.EMPTY);
        }
    }

    @Override
    public boolean isValidMove(int row, int col) {
        return row >= 0 && row < Chess.BOARD_SIZE && col >= 0 && col < Chess.BOARD_SIZE
                && board[row][col] == Chess.EMPTY;
    }

    @Override
    public boolean placeChess(int row, int col) {
        if (!isValidMove(row, col))
            return false;
        board[row][col] = player.isCurrentPlayer1() ? Chess.PLAYER1_SYMBOL : Chess.PLAYER2_SYMBOL;
        player.switchPlayer();
        return true;
    }

    @Override
    public boolean isGameOver() {
        for (char[] row : board) {
            // 加强for循环，遍历行
            // 这里的row是一个一维数组，表示棋盘的一行
            // 如果行中有空格，说明游戏没有结束，返回false
            for (char cell : row) {
                if (cell == Chess.EMPTY)
                    return false;
            }
        }
        return true;
    }

    @Override
    public String getScoreInfo() {
        return ""; // Peace模式无得分
    }
}